home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Tools 4
/
Amiga Tools 4.iso
/
tools
/
internet-tools
/
internet-install-tools
/
varknet3
/
net3.lha
/
AmiTCP-4.0
/
bin
/
netstat
< prev
next >
Wrap
Text File
|
1994-10-03
|
13KB
|
360 lines
/* sys:rexxc/rx
* Hey Emacs! This file is -*- rexx -*-
*
* $Id: netstat,v 4.1 1994/10/03 20:38:11 jraja Exp $
*
* $VER: netstat 4.1 (3.10.94)
*
* Copyright © 1994 AmiTCP/IP Group,
* Network Solutions Development Inc.
* All rights reserved.
*/
ARG opt args
if left(opt,1)~='-' then do
args=opt
opt=''
end
args=strip(args)
numeric=0
if pos('N',opt)~=0 then numeric=1
resolver = 'APIPE:AmiTCP:bin/resolve'
resolved. = ''
services. = ''
ALL = 0
tab = " "
if args = "ALL" then ALL=1 /* All information wanted */
options results /* Results from external command wanted */
address AMITCP /* default command host is AMITCP */
RESULT = "" /* Set so that it don't get value RESULT */
if args = "" | args = "ALL" then do
/* States of TCP finite state machine */
state.0 = "CLOSED"
state.1 = "LISTEN"
state.2 = "SYN_SENT"
state.3 = "SYN_RECV"
state.4 = "ESTABLISHED"
state.5 = "CLOSE_FIN"
state.6 = "CLOSED_FIN"
state.7 = "FINACK_WAIT"
state.8 = "CLOSED_FINACK"
state.9 = "CLOSED"
state.A = "TIME_WAIT"
'QUERY' 'CONNECTIONS' /* Ask information */
/* Print header */
say "Proto Recv-Q Send-Q Local Address Foreign Address (status)"
rest = result
do while (rest ~= "")
/* Parse result string */
parse upper value rest with pr rq sq la lp fa fp st rest
/* Print only if connection is non-listening or all connections wanted */
if all = 1 | (st ~= 0 & st ~= 1) then do
if pr=t then do
pro = "tcp" /* Protocol */
sts = state.st /* Name of state */
end
else do
pro = "udp"
sts = "" /* udp is stateless */
end
say left(pro, 5) right(x2d(rq), 6) right(x2d(sq), 6),
left(" " || GetSocketName(la, lp, pro), 23),
left(" " || GetSocketName(fa, fp, pro), 23) "" sts
end
end /* while */
end /* connections */
/* If status wanted */
if left(args,6) = "STATUS" then do
/* Ask ICMP information */
'Q' ICMP CHksum ICMP COde ICMP Error ICMP Icmpold ICMP Length ICMP Tooshort ICMP Responses ICMP Shortold
/* Parse ICMP information */
parse value result with icps_checksum icps_badcode icps_error icps_oldicmp icps_badlen icps_reflect icps_oldshort icps_tooshort .
/* Ask and parse IP information */
'Q' IP CH IP D IP FC IP FD IP FE IP FO IP FS IP FT IP FW IP H IP LE IP LO IP N IP OD IP OF IP REA IP RED IP TOOSH IP TOOSM IP TOTAL
parse value result with ips_badsum ips_delivered ips_cantfragment ips_fragdropped ips_fragmented ips_forward ips_fragments ips_fragtimeout ips_cantforward ips_badhlen ips_badlen ips_localout ips_noproto ips_odropped ips_ofragments ips_reassembed ips_redirectsent ips_tooshort ips_toosmall ips_total .
/* Ask and parse TCP information */
'Q' TCP Accepts TCP CAttem TCP CDrops TCP CLosed TCP COnnect TCP DElack TCP DRops TCP KADrops TCP KAProbe TCP KATimeo TCP Persist TCP RACKByte TCP RACKPack TCP RACKToom TCP RAFter TCP RBLate TCP RBYte TCP RChksum TCP RDUPAck TCP RDUPByte TCP RDUPPack TCP ROFfset TCP ROOByte TCP ROOPack TCP RPAck TCP RPDUPByte TCP RPDUPData TCP RPLate TCP RPShort TCP RTOtal TCP RTTupdate TCP RWProbe TCP RWUpdate TCP SAcks TCP SByte TCP SCtrl TCP SEgstimed TCP SPack TCP SREByte TCP SREPack TCP STotal TCP SUrgent TCP SWProbe TCP SWUpdate TCP Timeodrop TCP RExmtt
parse value result with tcps_accepts tcps_connattempt tcps_conndrops tcps_closed tcps_connects tcps_delack tcps_drops tcps_keepdrops tcps_keepprobe tcps_keeptimeo tcps_persisttimeo tcps_rcvackbyte tcps_rcvackpack tcps_rcvacktoomuch tcps_rcvafterclose tcps_rcvbyteafterwin tcps_rcvbyte tcps_rcvbadsum tcps_rcvdupack tcps_rcvdupbyte tcps_rcvduppack tcps_rcvbadoff tcps_rcvoobyte tcps_rcvoopack tcps_rcvpack tcps_rcvpartdupbyte tcps_rcvpartduppack tcps_rcvpackafterwin tcps_rcvshort tcps_rcvtotal tcps_rttupdated tcps_rcvwinprobe tcps_rcvwinupd tcps_sndacks tcps_sndbyte tcps_sndctrl tcps_segstimed tcps_sndpack tcps_sndrexmitbyte tcps_sndrexmitpack tcps_sndtotal tcps_sndurg tcps_sndprobe tcps_sndwinup tcps_timeoutdrop tcps_rexmttimeo .
/* Ask and parse UDP information */
'Q' UDP Bcnoport UDP Chksum UDP Fullsoc UDP Headshort UDP Itotal UDP Length UDP Mispcb UDP Noport UDP Ototal
parse value result with udps_noportbcast udps_badsum udps_fullsock udps_hdrops udps_ipackets udps_badlen udps_pcbcachemiss udps_noport udps_opackets .
/* Ask ICMP history */
'Q' ICMPHIST
icmphist = result
say "tcp:"
say tab || tcps_sndtotal "packets sent"
say tab || tab || tcps_sndpack "data packets ("||tcps_sndbyte "bytes)"
say tab || tab || tcps_sndrexmitpack "data packets ("||tcps_sndrexmitbyte "bytes) retransmitted"
say tab || tab || tcps_sndacks "ack-only packets ("|| tcps_delack "delayed)"
say tab || tab || tcps_sndurg "URG only packets"
say tab || tab || tcps_sndprobe "window probe packets"
say tab || tab || tcps_sndwinup "window update packets"
say tab || tab || tcps_sndctrl "control packets"
say tab || tcps_rcvtotal "packets received"
say tab || tab || tcps_rcvackpack "acks (for" tcps_rcvackbyte "bytes)"
say tab || tab || tcps_rcvdupack "duplicate acks"
say tab || tab || tcps_rcvacktoomuch "acks for unsent data"
say tab || tab || tcps_rcvpack "packets ("|| tcps_rcvbyte "bytes) received in-sequence"
say tab || tab || tcps_rcvduppack "completely duplicate packets ("|| tcps_rcvdupbyte "bytes)"
say tab || tab || tcps_rcvpartduppack "packets with some dup. data ("|| tcps_rcvpartdupbyte "bytes duped)"
say tab || tab || tcps_rcvoopack "out-of-order packets ("||tcps_rcvoobyte "bytes)"
say tab || tab || tcps_rcvpackafterwin "packets ("||tcps_rcvbyteafterwin "bytes) of data after window"
say tab || tab || tcps_rcvwinprobe "window probes"
say tab || tab || tcps_rcvwinupd "window update packets"
say tab || tab || tcps_rcvafterclose "packets received after close"
say tab || tab || tcps_rcvbadsum "discarded for bad checksum"
say tab || tab || tcps_rcvbadoff "discarded for bad header offset fields"
say tab || tab || tcps_rcvshort "discarded because packet too short"
say tab || tcps_connattempt "connection requests"
say tab || tcps_accepts "connection accepts"
say tab || tcps_connects "connections established (including accepts)"
say tab || tcps_closed "connections closed (including" tcps_drops "drops)"
say tab || tcps_conndrops "embryonic connections dropped"
say tab || tcps_rttupdated "segments updated rtt (of" tcps_segstimed "attempts)"
say tab || tcps_rexmttimeo "retransmit timeouts"
say tab || tab || tcps_timeoutdrop "connections dropped by rexmit timeout"
say tab || tcps_persisttimeo "persist timeouts"
say tab || tcps_keeptimeo "keepalive timeouts"
say tab || tab || tcps_keepprobe "keepalive probes sent"
say tab || tab || tcps_keepdrops "connections dropped by keepalive"
say "udp:"
say tab || udps_hdrops "incomplete headers"
say tab || udps_badlen "bad data length fields"
say tab || udps_badsum "bad checksums"
say "ip:"
say tab || ips_total "total packets received"
say tab || ips_badsum "bad header checksums"
say tab || ips_tooshort "with size smaller than minimum"
say tab || ips_toosmall "with data size < data length"
say tab || ips_badhlen "with header length < data size"
say tab || ips_badlen "with data length < header length"
say tab || ips_fragments "fragments received"
say tab || ips_fragdropped "fragments dropped (dup or out of space)"
say tab || ips_fragtimeout "fragments dropped after timeout"
say tab || ips_forward "packets forwarded"
say tab || ips_cantforward "packets not forwardable"
say tab || ips_redirectsent "redirects sent"
/* ICMP codes */
icmph. = "UNKNOWN" /* default */
icmph.0 = "Echo reply"
icmph.3 = "Destination unreachable"
icmph.4 = "Packet lost, slow down"
icmph.5 = "Shorter route"
icmph.8 = "Echo service"
icmph.11 = "Time exceeded"
icmph.12 = "IP header bad"
icmph.13 = "Timestamp request"
icmph.14 = "Timestamp reply"
icmph.15 = "Information request"
icmph.16 = "Information reply"
icmph.17 = "Address mask request"
icmph.18 = "Address mask reply"
/* First out, then in statistics */
say "icmp:"
do a = 0 to 1
if a = 0 then do
say tab || icps_error "calls to icmp_error"
say tab || icps_oldicmp "errors not generated 'cuz old message was icmp"
say tab || "Output histogram:"
end
else do
say tab || icps_badcode "messages with bad code fields"
say tab || icps_tooshort "messages < minimum length"
say tab || icps_checksum "bad checksums"
say tab || icps_badlen "messages with bad length"
say tab || "Input histogram:"
end
do b = 0 to 18
count = subword(icmphist, a*19 + b + 1, 1)
if count ~= 0 then say tab || tab || count "times" icmph.b
end
end
say tab || icps_reflect "message responses generated"
end /* end STATUS */
/*
* Dump routing table
*/
if left(args, 5) = "ROUTE" then do
afamily.1 = "Unix";
afamily.2 = "Internet Protocols";
afamily.3 = "Arpanet IMP Addresses";
afamily.4 = "PUP Protocols";
afamily.5 = "MIT CHAOS";
afamily.6 = "XEROX NS ";
afamily.7 = "ISO Protocols";
afamily.8 = "ECMA";
afamily.9 = "Datakit Protocols";
afamily.10 = "CCITT (X.25) Protocols";
afamily.11 = "IBM SNA";
afamily.12 = "DECnet";
afamily.13 = "DEC Direct Data Link Interface";
afamily.14 = "LAT";
afamily.15 = "NSC Hyperchannel";
afamily.16 = "Apple Talk";
afamily.17 = "Internal Routing Protocol";
afamily.18 = "Link layer interface";
afamily.19 = "eXpress Transfer Protocol";
'QUERY ROUTES ALL' /* Ask information */
oldaf = -1;
rest = result;
do while rest ~= ""
parse value rest with af dest gate flags refs used iface rest
/* Print address (protocol) family */
af=x2d(af);
if af ~= oldaf then do
/* Print header */
if af ~= 0 then do
say "Routing table for" afamily.af
say "Destination Gateway Flags Refs Use Interface"
end; else do
say "Netmasks"
end
oldaf = af;
end
/* Print routes */
if (af == 2) then do
/* Convert addresses to decimal dot notation */
if (numeric | index(flags, 'H') = 0) then do
if (dest == "00000000") then do
desta = "default"
end; else do
desta = hex2inet(dest)
end
gatea = hex2inet(gate)
end; else do
desta = resolve(dest)
gatea = resolve(gate)
end
/* Print route */
say left(desta, 20) left(gatea, 20) left(flags, 8),
right(x2d(refs), 4) right(x2d(used), 8) "" iface;
end
else do
say hex2inet(dest)
end
end /* while rest */
end /* ROUTE */
exit
/*
* Using the AmiTCP 3.0 'resolve' command, this subroutine tries to convert
* the ip address into a canonical name of the host.
* (by Pavel Troller <patrol@k332.feld.cvut.cz>)
*
* The resolved names are cached into the "resolved.". If resolving fails,
* the address is inserted to the cache to prevent resolving the same
* address again.
* (jraja)
*
* Nets and default route are handled by main routine. The error
* messages are now handled. The argument should be in hex format.
* (by ppessi)
*/
resolve: procedure expose resolved. resolver
parse arg resadr .
resname = resolved.resadr
if resname = '' then do
/* As x2d is signed this is needed for IP addresses > 128.0.0.0 */
ipaddr = x2d(substr(resadr,1,2)) || "." || x2d(substr(resadr,3,6))
success = open(rfile, resolver || ' ' || ipaddr, 'R')
if (success) then do
parse value readln(rfile) with keyword bla resnamemaybe .
call close(rfile)
end
if (success & keyword = 'HOST') then do
resname = resnamemaybe
end
else do
resname = hex2inet(resadr)
end
resolved.resadr = resname
end
/*
* Add the resolved name to cache
*/
return resname
/*
* Get the socket name (host.service)
*/
GetSocketName: procedure expose resolver services. resolved. numeric
parse arg address, port, protocol
/* Convert addresses to human readable form */
if (address = 0) then do
hostname = "*";
end; else if (numeric) then do
hostname = hex2inet(address);
end; else do
hostname = resolve(address);
end
if (port = 0) then do
service = "*";
end;
else if (numeric) then do
service = x2d(port);
end;
else do
service = services.protocol.port
if service = '' then do
service = x2d(port);
success = open(rfile, resolver||' port '||service||' '||protocol, 'R');
if (success) then do
parse value readln(rfile) with keyword servicemaybe .;
call close(rfile);
end
if (success & keyword = 'SERVICE') then do
service = servicemaybe;
end
/*
* Add the service name to cache
*/
services.protocol.port = service;
end
end
return hostname||"."||service;
/*
* Convert Inet address (in hex) into dot notation
*/
hex2inet: procedure
parse arg haddr .
inetaddr = x2d(substr(haddr,1,2)) || "." || x2d(substr(haddr,3,2)) ||,
"." || x2d(substr(haddr,5,2)) || "." || x2d(substr(haddr,7,2))
return inetaddr